<?php
namespace my\bq\dao;

use my\bq\dao\DaoSupport;
use my\bq\dao\PdoManager; 
use my\bq\criterion\CriteriaImpl;
use dao\OrderDao;

class DaoTemplate{
	
	protected function save($entity){
		$arrayId = array();
		if(is_array($entity)){
			foreach ($entity as $object){
				$id = DaoSupport::saveEntity($object);
			}
			
		}else{
			return DaoSupport::saveEntity($entity);
		}
		return false;
	}
	
	protected function delete($entity){
		return DaoSupport::deleteEntity($entity);
	}
	
	protected function update($entity){
		return DaoSupport::updateEntity($entity);
	}
	
	public function find($criteria){
		$rs = $criteria->_array();
		if(is_array($rs)){
			return @current($rs);
		}
	}
	
	public function findAll($criteria){
		return $criteria->_array();
	}
	
	public function findBySQL($sql){
		$pdoManager = PdoManager::getInstance();
		$pdo = $pdoManager->getPdo();
		return $pdo->query($sql);
	}
	
	
}